Here we explore the oil spill incidents that were reported to California Emergency Management Agency in 2008. Many of the oil spill were reported in counties along the coast and the San Francisco Bay Area. Los Angeles county had the largest number of reports oil spill incidents.
# Read in the Oil Spill data
incidents <- read_sf(here("data",layer = "Oil_Spill_Incident_Tracking_%5Bds394%5D.shp")) %>%
clean_names() %>%
mutate(incident_date = date(dateofinci)) %>%
rename(county_name = localecoun) # Rename county name column to be consistent with the other dataset
# Read in California counties data
ca_counties <- read_sf(here("data","CA_counties","CA_counties.shp")) %>%
clean_names() %>%
select(name, aland) %>%
rename(county_name = name, land_area = aland) # Rename county name column to be consistent with the other dataset
# Check crs for the datasets
#st_crs(ca_counties) # `ca_counties` was loaded in as 4326
#st_crs(incidents) # `incidents` was loaded in as 3857
ca_counties <- st_transform(ca_counties, 3857) # transform so the datasets are the same, this is important for the `st_join()` later. I chose 3857 because in is a projected coordinated system that is widely used. 4326 is a geographic coordinate system
#st_crs(ca_counties) # Check crs to ensure the `st_transform()` worked
# Make and interactive map to show the locations of oil spill events
# Set the viewing mode to `interactive`/"view":
tmap_mode(mode = "view")
# Make a map with the fill color updated to variable 'county_name'
tm_shape(ca_counties) +
tm_fill("county_name", palette = "BuGn", title =" ") +
tm_shape(incidents) + # Add a layer for the oil spill indicents and have the events plotted as dots
tm_dots()+
labs(title = "Oil Spill Events")